//
//  HPVisitorViewController.swift
//  MyWeibo
//
//  Created by Apeng on 16/4/8.
//  Copyright © 2016年 Apengpeng. All rights reserved.
//

import UIKit

class HPVisitorViewController: UITableViewController, HPVisitorViewDelegate {
    // 全局变量
    var isLogin = HPUserAccountViewModel.sharedUserAccountViewModel.isLogin
    var visitorView :HPVisitorView?
    
    // loadView 中判断视图
    override func loadView() {
        isLogin ? super.loadView() : prepareForVisitorView()
    }
    
    // 加载访客视图
    private func prepareForVisitorView() {
        visitorView = HPVisitorView()
        visitorView?.delegate = self
        view = visitorView
        
        // nav 的跟视图就是访客视图
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "go2Login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "go2Register")
    }
    
    
    // 代理方法
    func go2Login() {
        print("go2Login")
        
        let OAthVC = HPOAuthViewController()
        let nav = UINavigationController(rootViewController: OAthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func go2Register() {
        print("go2Register")
    }
}
